home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: strncpy() ?
- Date: 21 Apr 1996 11:08 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <21APR199611080510@erich.triumf.ca>
- References: <4ldkvd$553@venus.compulink.gr>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4ldkvd$553@venus.compulink.gr>, lonewolf@athena.compulink.gr (Costas Vlassis) writes...
- >
- > Well I have this question, let's say we have the following :
- >
- >char alfa[40] = "1123";
- >char beta[20];
- >char gama[20];
- >
- >With strncpy(beta,alfa,2) beta = "11" that's fine but HOW can I make
- >gama = "23" that is the last 2 characters of alfa or even "3" the last
- >character... Is there a function that takes start and end as strings ?
- >
- >what I want is something like :
- >
- >strncpy2 (beta,alfa,2,4);
-
- strncpy(gamma, alfa+2, 2);
- will (if I've counted correctly) copy "23" to gamma.
-
- Beware that strncpy() usually does _not_ terminate what it copies with '\0', so
- you will have to do that manually to make these legal C strings.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
- or: http:://vancouver-webpages.com/peter/index.html
-
-
-
-
-